#ifndef AJ_SESSIONINFO_H
#define AJ_SESSIONINFO_H

#include <QObject>
#include "aj_tcpsession.h"
#include <QMutex>
#include <QTimer>
#include <QTime>
#include <QQueue>
#include <QJsonObject>

class SessionInfo : public QObject
{
    Q_OBJECT
signals :
    void SignalRead(SessionInfo*, const QByteArray &, int);
    //void SignalDisconnect(QString strIp);
    //void SignalConnected();

public:
    SessionInfo(std::shared_ptr<NETAPI::TcpSession> &session);
    ~SessionInfo();

    void Connect(const QString &host, quint16 port);
    void Disconnect();
    void Write(const char*buffer, int size);
    QString getIp(){ return m_strIp; };
    void replyJsonObject(const QJsonObject &jsonObject, const int &httpStatusCode);
    void analyseBufferSetup1();
    void analyseBufferSetup2();
    QJsonObject byteArrayToJson(const QByteArray &byteArray);
    bool fkeyCheck(QString strMac,QString strTimestamp,QString strFkey);
    void refreashCache();

public:
    //断开连接回调
    std::function<void(void*)> OnDisConnected = nullptr;

public slots:
    void SlotRead(const QByteArray &data, int size);
    void SlotDisconnected();
    void SlotOverTimer();
    void SlotReceiveFaceFeature(QString strFilename,QByteArray faceFeture);
    void SlotUpdateInfoFinished(bool success,int cmd);
    //void SlotUpdateVersionStatus(int status);//0未完成,1已完成,2处理中,3失败

signals:
    void SignalProcessRequest(int cmd,QStringList para);


private:
    std::shared_ptr<NETAPI::TcpSession> Session_;
    QString m_strIp;
    QString m_strStandardIp;
    QTimer* m_overTimer;

    QByteArray receiveBuffer_;
    QString                  requestSourceIp_;
    QString                  requestMethod_;
    QString                  requestUrl_;
    QString                  requestCrlf_;
    QByteArray               requestBody_;
    QMap< QString, QString > requestHeader_;

    bool   headerAcceptedFinished_  = false;
    bool   contentAcceptedFinished_ = false;
    qint64 contentLength_           = -1;


    QJsonObject m_jsonObject;
    QString m_strFilename;

    int m_lastOperationRecordId;
};


#endif // AJ_SESSIONINFO_H
